<?php
/**
 * Created by JetBrains PhpStorm.
 * User: andrei
 * Date: 7/31/12
 * Time: 1:35 PM
 * To change this template use File | Settings | File Templates.
 */


class Db_Cms_PageTypes extends Common {
    protected static $tableName = TAB_PAGE_TYPES;
    protected static $dbFields = array(
        'id',
        'pt_title',
        'pt_show_header',
        'pt_alt_header', // todo
        'pt_show_footer',
        'pt_alt_footer', // todo
        'deleted'
    );

    /**
     * @var Db_Cms_PageTypes
     */
    public $objectArray;

    public $id;
    public $pt_title;
    public $pt_show_header;
    public $pt_alt_header;
    public $pt_show_footer;
    public $pt_alt_footer;
    public $deleted;

    function __construct($value=NULL, $fieldName=NULL) {
        parent::__construct($value, $fieldName);
    }

	public static function getAllPageTypes() {
		$sql = 'SELECT `pt`.*, IF(`pt`.`id` = `p`.`p_type_id`, 1, 0) AS `is_used` FROM ?f `pt`
				LEFT JOIN ?f AS `p` ON `pt`.`id` = `p`.`p_type_id` AND `p`.`deleted` = 0
				WHERE `pt`.`deleted` = 0
				GROUP BY `pt`.`id`';
		return self::$DB->select($sql, self::$tableName, TAB_PAGES);
	}
}